var mysql = require('mysql');
var mysql_config = require("./../../util/mysql_config");
var log = require("./../../util/loginfo").getInstand;

var pool = mysql.createPool({
    connectionLimit: 10000,
    host: mysql_config.host,
    user: mysql_config.user,
    password: mysql_config.password,
    port: mysql_config.port,
    database: 'gameaccount',
    charset: "utf8mb4",
});

//上下分记录
exports.insert_mark = function insert_mark(userInfo) {
    var sql = "INSERT INTO mark(userId,useCoin,winCoin,tax,gameId,serverId) VALUES(?,?,?,?,?,?)";
    var values = [];
    pool.getConnection(function (err, connection) {

        for (var i = 0; i < userInfo.length; i++) {
            if (userInfo[i].userId < 500 || userInfo[i].userId > 1800) {
                values.push(userInfo[i].userId);
                values.push(userInfo[i].useCoin);
                values.push(userInfo[i].winCoin);
                values.push(userInfo[i].tax);
                values.push(userInfo[i].gameId);
                values.push(userInfo[i].serverId);

                connection.query({sql: sql, values: values}, function (err, rows) {

                    if (err) {
                        log.info("insert_mark");
                        log.err(err);
                    }
                });

                values = [];
            }
        }
        connection.release();

    });
};